﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model.ProviderDataSetTableAdapters;
using Model._IRepository;

namespace Model.Repository
{
    public class MembersRepository : _IMembersRepository
    {
        ProviderDataSet DS_Providers = new ProviderDataSet();
        tbl_MembersTableAdapter TA_Members = new tbl_MembersTableAdapter();
        ProviderDataSet.tbl_MembersDataTable DT_Members;

        public bool ValidateUser(string Username, string Password)
        {
            try
            {
                return Convert.ToBoolean(TA_Members.IsMember(Username, Password));
            }
            catch (Exception ex)
            {
                return false;
            }
        }


        public void CreateUser(string Firstname, string Middlename, string Lastname, string Gender, string Email, string Alt_Email, string BusinessPhone, string MobilePhone, string Username, string Password, string PasswordQuestion, string PasswordAnswer)
        {
            try
            {
                DateTime NOW = DateTime.Now;
                TA_Members.Insert(Guid.NewGuid(), Firstname, Middlename, Lastname, Gender, Email, Alt_Email, BusinessPhone, MobilePhone, Username, Password, PasswordQuestion, PasswordAnswer, false, true, NOW, NOW);                
            }
            catch (Exception ex)
            {
            }
        }
       

        public string GetNameByUsername(string Username)
        {
            try
            {
                return TA_Members.GetNameByUsername(Username) as string;
            }
            catch (Exception ex)
            {
                return string.Empty;
            }
        }


        public object GetUser(string username, bool IsActive)
        {
            // http://stackoverflow.com/questions/5556031/implement-custom-membershipuser-and-custom-membershipprovider
        }
    }
}
